package org.jeecg.modules.generator.service.impl;

import java.util.List;
import org.jeecg.modules.generator.vo.SysGenerateDatabaseConfigVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.generator.entity.SysGenerateDatabaseConfig;
import org.jeecg.modules.generator.service.SysGenerateDatabaseConfigService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.jeecg.modules.generator.mapper.SysGenerateDatabaseConfigMapper;
import org.apache.commons.lang3.StringUtils;


/**
* @Description 数据源配置表服务
* @Author yangfeng
* @Date 2021-06-29 17:28:26
*/
@Service
@Transactional
public class SysGenerateDatabaseConfigServiceImpl extends ServiceImpl<SysGenerateDatabaseConfigMapper, SysGenerateDatabaseConfig> implements SysGenerateDatabaseConfigService {


        /**
        * 根据查询条件导出数据源配置表列表
        * @param sysGenerateDatabaseConfigVo
        * @return
        */
        public List<SysGenerateDatabaseConfig> exportEntityList(SysGenerateDatabaseConfigVo sysGenerateDatabaseConfigVo){

            QueryWrapper  queryWrapper = new QueryWrapper();
            if(sysGenerateDatabaseConfigVo.getIdList() !=null && sysGenerateDatabaseConfigVo.getIdList().size()>0){
                queryWrapper.in("ID",sysGenerateDatabaseConfigVo.getIdList());
            }else{
                if(StringUtils.isNotEmpty(sysGenerateDatabaseConfigVo.getUsername())){
                    queryWrapper.like("USERNAME",sysGenerateDatabaseConfigVo.getUsername());
                }
                if(StringUtils.isNotEmpty(sysGenerateDatabaseConfigVo.getName())){
                    queryWrapper.like("NAME",sysGenerateDatabaseConfigVo.getName());
                }
                if(StringUtils.isNotEmpty(sysGenerateDatabaseConfigVo.getDatabaseType())){
                    queryWrapper.eq("DATABASE_TYPE",sysGenerateDatabaseConfigVo.getDatabaseType());
                }
            }
            List<SysGenerateDatabaseConfig> sysGenerateDatabaseConfigList = this.list(queryWrapper);
            return sysGenerateDatabaseConfigList;
        }

        /**
        * 保存excel导入的数据
        * @param sysGenerateDatabaseConfigList
        */
        public void importEntityList(List<SysGenerateDatabaseConfig> sysGenerateDatabaseConfigList){
            this.saveBatch(sysGenerateDatabaseConfigList);
        }
}
